<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['member']=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit6','mobile','avatar','nickname'));
	$this->model('model')->up_task();
	$return['pluginset']['hdps']=$return['pluginset']['canghdps'];
	$return['pluginset']['bankuai']=$return['pluginset']['cangbankuai'];
	$sharelink='jy_nongfee/cang//fromuser='.$_SESSION['uid'];
	$return['sharedata']=array(
			'title'=>$this->setting['share_title']?:'种植众筹-在线抢购',
			'desc'=>$this->setting['share_desc']?:'种植众筹，参与'.$this->cd_title.'种植！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>ATTACHMENT_URL.$return['pluginset']['logo']
	);
	if($this->setting['tpl_type']){
		//$return['htmls']=$this->template_url('cang1');
	}
	set_html('title',$this->setting['cang_title']?:'种植众筹');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['keyword']){
		$params['title like']='%;'.$_RQ['keyword'].';%';
	}
    $orderby='createtime desc';
	$total='';
	$list=pdo_getslice('jy_nongfee_cang',$params,array($pindex,$psize),$total,'','','id desc');
	if($list){
		$day=date('Y/m/d');
		foreach($list as &$item){
			$item=$this->model('model')->up_canginfo($item);
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['salenum']=pdo_count('jy_nongfee_canlog',array('uniacid'=>$_SESSION['uniacid'],'cangid'=>$item['id']),'id');
			$item['statustitle']=$this->cang_status2[$item['status']];
			$item['yao']=pdo_get('jy_nongfee_yao',array('cangid'=>$item['id'],'status'=>1,'uniacid'=>$_SESSION['uniacid']));
			if($item['yao']['id']){
				$item['isfee']=pdo_getsum('jy_nongfee_canlog',array('yaoid'=>$item['yao']['id'],'cangid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'jifen');
				$item['israte']=$item['isfee']?$item['isfee']/$item['yao']['alljifee']:0;
				$item['yao']['statustitle']='种植中';
			}else{
				$item['yao']=pdo_get('jy_nongfee_yao',array('cangid'=>$item['id'],'status'=>0,'uniacid'=>$_SESSION['uniacid']),'','id asc');
				if($item['yao']['id']){
					$item['israte']=0;
					$item['yao']['statustitle']='预约中';
				}else{
					$item['yao']=pdo_get('jy_nongfee_yao',array('cangid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'','id desc');
					$item['yao']['statustitle']='已结束';
				}
			}
			if(!$item['status']){
				$start_time=$item['yao']['startime'];
				if(TIMESTAMP>$start_time){
					$item['isstart']=1;
					$rest_time=$item['yao']['endtime'];
				}else{
					$item['isstart']=0;
					$rest_time=$start_time;
					$dayhour=date('H:i',$start_time);
					$item['statustitle']=$dayhour.'开始';
				}
				$item['end_time']=$end_time;
				$item['rest_time']=model('jy_weishop/model')->date($rest_time-TIMESTAMP);
			}
			$pindex = max(1, 0);
			$psize = 4;
			$members=pdo_getslice('jy_nongfee_canlog',array('uniacid'=>$_SESSION['uniacid'],'cangid'=>$item['id']),array($pindex,$psize),$total,array('mid'),'','id desc');
			foreach($members as &$mv){
				$memberinfo=pdo_get('core_members',array('id'=>$mv['mid']),array('nickname','avatar'));
				$mv['nickname']=$memberinfo['nickname'];
				$mv['avatar']=$memberinfo['avatar'];
			}
			$item['members']=$members;
			$item['subtitle']='最低可投入('.$item['jian_jinmin'].')'.$this->cd_title.',第'.$item['nowyaonum'].'期最高可投入('.$item['yao']['jian_jinmax'].')'.$this->cd_title.'';
		}
	}
	$return['list']=$list;
	exi($return);
}
?>